﻿using DuBaiCoffee2.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;

namespace DuBaiCoffee2
{
    public class DY
    {
        private static DY instance;
        private DY() { }

        public static DY Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new DY();
                }
                return instance;
            }
        }
        public void DyCS(string path)
        {
            try
            {
                using (var cvt = new JmPrint.Converter(JmPrint.PrinterType.Color, "revert=0:duplex=120"))
                {
                    var imgPath = path;
                    //cvt.ConvertImage(imgPath, 180, 180);
                    //cvt.ConvertImage(imgPath, 720, 720);
                    cvt.ConvertImage(imgPath, 600, 600);
                    var data = cvt.GetData();
                    using (var usbmgr = new USB.Manager())
                    {
                        var dd = usbmgr.Open(0);
                        var dd2 = usbmgr.Write(data);
                        usbmgr.Close();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
    }
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public static bool isMake = true;
        public static double MakingTypes = 0;
        public static string img_path = "";
        public static List<GoodsMsg> goodsMsgs = new List<GoodsMsg>();
        public static string GoodsUrl = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"GoodsMessage.txt";
        public static string IPorPortUrl = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"IPorPortMessage.txt";
        /// <summary>
        /// M12警告
        /// </summary>
        public static string WarnPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"Warn";
        /// <summary>
        /// M12故障
        /// </summary>
        public static string BreakPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"BreakDowm";
        public static bool IsStartMakingL = false;
        public static bool IsStartMakingR = false;
        public static DeviceOrderQueue list = new DeviceOrderQueue();
        public static string coffeeNameCode = "";
        public static string Img = "";
        public static int TypeL = -1;
        public static int sugarCode = 0;
        public static int cupCode = 0;
        public static int BeanCode = 1;
        public static int zsInit = 0;
        public MainWindow()
        {
            InitializeComponent();
        }
        public static string EmailError()
        {
            try
            {
                string msg = "<style>table{ border: 1px solid black; border-collapse: collapse; }table td{border: 1px solid #000000; padding: 5px 15px;font-size:14px;}</style><table>";
                if (WuLiaoCoffeeSel.Instance.CoffeeBean_Sel_Bol)
                    msg += "<tr><td style='font-weight:bold;'>CoffeeBean</td><td>adequate materials</td></tr>";
                else
                    msg += "<tr><td style='font-weight:bold;'>CoffeeBean</td><td style='color:#FF0000;'>Lack of material</td></tr>";
                if (!WuLiaoCoffeeSel.Instance.Milk_Sel_Bol)
                    msg += "<tr><td style='font-weight:bold;'>Milk</td><td style='color:#FF0000;'>Lack of material</td></tr>";
                else
                    msg += "<tr><td style='font-weight:bold;'>Milk</td><td>adequate materials</td></tr>";
                if (WuLiaoCoffeeSel.Instance.CupFeed1_Sel_Bol)
                    msg += "<tr><td style='font-weight:bold;'>Cup1</td><td>adequate materials</td></tr>";
                else
                    msg += "<tr><td style='font-weight:bold;'>Cup1</td><td style='color:#FF0000;'>Lack of material</td></tr>";
                msg += "</table>";
                return msg;
            }
            catch (Exception)
            {
                return "";
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!File.Exists(IPorPortUrl))
                {
                    using (FileStream stream = File.Create(IPorPortUrl))
                    {
                        stream.Close();
                        stream.Dispose();
                        IPorPortInfo porPortInfo1 = IPorPortInfo.Instance;
                        File.WriteAllText(IPorPortUrl, JsonConvert.SerializeObject(porPortInfo1));
                    }
                }
                else
                {
                    var dd = File.ReadAllText(IPorPortUrl);
                    var porPortInfo = JsonConvert.DeserializeObject<IPorPortInfo>(File.ReadAllText(IPorPortUrl));
                    IPorPortInfo.Instance.url_start = porPortInfo.url_start;
                    IPorPortInfo.Instance.DeviceId = porPortInfo.DeviceId;
                    IPorPortInfo.Instance.CoffeeIP = porPortInfo.CoffeeIP;
                    IPorPortInfo.Instance.CoffeePort = porPortInfo.CoffeePort;
                    IPorPortInfo.Instance.RobotIPLeft = porPortInfo.RobotIPLeft;
                    IPorPortInfo.Instance.RobotIPRight = porPortInfo.RobotIPRight;
                    IPorPortInfo.Instance.PortName = porPortInfo.PortName;
                    IPorPortInfo.Instance.PortNameR = porPortInfo.PortNameR;
                    IPorPortInfo.Instance.PrinterCoffeeIP = porPortInfo.PrinterCoffeeIP;
                    IPorPortInfo.Instance.PrinterCofferPort = porPortInfo.PrinterCofferPort;
                    IPorPortInfo.Instance.EWMPortName = porPortInfo.EWMPortName;
                    IPorPortInfo.Instance.ZBPortName = porPortInfo.ZBPortName;
                    IPorPortInfo.Instance.CoffeePortName = porPortInfo.CoffeePortName;
                    IPorPortInfo.Instance.SugarInit1 = porPortInfo.SugarInit1;
                    IPorPortInfo.Instance.SugarInit2 = porPortInfo.SugarInit2;
                    IPorPortInfo.Instance.SugarInit3 = porPortInfo.SugarInit3;
                    IPorPortInfo.Instance.RobotPortLeft = porPortInfo.RobotPortLeft;
                    IPorPortInfo.Instance.RobotPortRight = porPortInfo.RobotPortRight;
                    IPorPortInfo.Instance.IceMsg = porPortInfo.IceMsg;
                    IPorPortInfo.Instance.IceMsg2 = porPortInfo.IceMsg2;
                    IPorPortInfo.Instance.IceWaterMsg = porPortInfo.IceWaterMsg;
                    IPorPortInfo.Instance.IceTime = porPortInfo.IceTime;
                    IPorPortInfo.Instance.IceTime2 = porPortInfo.IceTime2;
                    IPorPortInfo.Instance.IceWaterTime = porPortInfo.IceWaterTime;
                    IPorPortInfo.Instance.LHPath = porPortInfo.LHPath;
                }
                try
                {
                    var GoodsList = JsonConvert.DeserializeObject<List<GoodsMsg>>(File.ReadAllText(GoodsUrl));
                    goodsMsgs.Clear();
                    GoodsList.ForEach(goodsMsgs.Add);
                }
                catch
                {
                }
                if (!Directory.Exists(WarnPath))
                {
                    Directory.CreateDirectory(WarnPath);
                }
                if (!Directory.Exists(WarnPath + @"\" + DateTime.Now.ToString("yyyy")))
                {
                    Directory.CreateDirectory(WarnPath + @"\" + DateTime.Now.ToString("yyyy"));
                }
                if (!Directory.Exists(WarnPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM")))
                {
                    Directory.CreateDirectory(WarnPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM"));
                }
                if (!Directory.Exists(WarnPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd")))
                {
                    Directory.CreateDirectory(WarnPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd"));
                }
                WarnPath = WarnPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd");
                if (!Directory.Exists(BreakPath))
                {
                    Directory.CreateDirectory(BreakPath);
                }
                if (!Directory.Exists(BreakPath + @"\" + DateTime.Now.ToString("yyyy")))
                {
                    Directory.CreateDirectory(BreakPath + @"\" + DateTime.Now.ToString("yyyy"));
                }
                if (!Directory.Exists(BreakPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM")))
                {
                    Directory.CreateDirectory(BreakPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM"));
                }
                if (!Directory.Exists(BreakPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd")))
                {
                    Directory.CreateDirectory(BreakPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd"));
                }
                BreakPath = BreakPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd");
                //VoiceSwitcher voiceSwitcher = new VoiceSwitcher();

                //// 切换到英式女声
                //voiceSwitcher.SwitchVoice("Microsoft Lily");

                //// 说一句话
                //voiceSwitcher.Speak("Hello, how are you doing today?");
                //SpeechSynthesizer synthesizer = new SpeechSynthesizer();
                //synthesizer.SetVoiceByLanguage("en-US");
                //synthesizer.Speak("Hello, this is a message in English.");
                Thread thr3 = new Thread(SocketClients.Instance.socketclient);
                thr3.IsBackground = true;
                thr3.Start();
                //CoffeeErversysMsg.Instance.Makelist();
                Thread thr = new Thread(IOMsg.Instance.IOSerial_Thr);
                thr.IsBackground = true;
                thr.Start();
                Thread thr9 = new Thread(coffeeMsg.Instance.IOSerial_Thr);
                thr9.IsBackground = true;
                thr9.Start();
                Thread thr6 = new Thread(IceMakingMsg.Instance.IOSerial_Thr);
                thr6.IsBackground = true;
                thr6.Start();
                Thread thr7 = new Thread(SocketClients.Instance.ClientL);
                thr7.IsBackground = true;
                thr7.Start();
                Thread thr8 = new Thread(SocketClients.Instance.ClientR);
                thr8.IsBackground = true;
                thr8.Start();
                Thread thr18 = new Thread(EWMMsg.Instance.IOSerial_Thr);
                thr18.IsBackground = true;
                thr18.Start();
                Thread thr2 = new Thread(DYCX);
                thr2.IsBackground = true;
                thr2.Start();
            }
            catch (Exception)
            {
                return;
            }
        }
        public void DYCX()
        {
            while (true)
            {
                try
                {
                    PwebSockets.Instance.DyCX();
                    Thread.Sleep(1000);
                    if (WuLiaoCoffeeSel.Instance.Print_Bol)
                    {
                        ClientList clientList = new ClientList();
                        clientList.MsgBol = WuLiaoCoffeeSel.Instance;
                        clientList.code = 2;
                        SocketClients.Instance.client.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                        break;
                    }
                }
                catch (Exception)
                {
                    Thread.Sleep(1000);
                }

            }
        }
        /// <summary>
        /// 全部订单查询
        /// </summary>
        public static void MessageShow()
        {
            while (true)
            {
                try
                {
                    Device device = new Device();
                    string lists = JsonConvert.SerializeObject(device);
                    var data = HttpMsg.Instance.deviceOrderQueueListMsg(lists);

                    if (data != null)
                    {
                        if (isMake)
                        {
                            var msglist = JsonConvert.DeserializeObject<HTTPMsg>(data);
                            if (msglist != null)
                            {
                                if (msglist.data.ToString().Length > 10)
                                {
                                    var list = JsonConvert.DeserializeObject<List<deviceOrderQueueList>>(msglist.data.ToString());
                                    if (list.Count > 0)
                                    {
                                        if (isMake)
                                        {
                                            zsInit = 0;
                                            if (list.Count > 0)
                                            {
                                                var ddd = list.FirstOrDefault(a => a.typeList2.Count > 0);
                                                if (ddd == null) continue;
                                                if (ddd.typeList2.Count > 0)
                                                {
                                                    var make = ddd.typeList2.FirstOrDefault(a => a.status == "3" || a.status == "4");
                                                    if (make != null)
                                                    {
                                                        if (make.jsonCodeVal.Length > 4)
                                                        {
                                                            var coffeecode = JsonConvert.DeserializeObject<List<specification>>(make.jsonCodeVal);
                                                            if (coffeecode.Count > 0)
                                                            {
                                                                var coffeeID = coffeecode.FirstOrDefault(a => a.classCode != "");
                                                                if (coffeeID != null)
                                                                {
                                                                    bool robotL = RobotModelLeft.Instance.LRobotJQRYX_Sel();
                                                                    bool robotR = RobotModelRight.Instance.RRobotJQRYX_Sel();

                                                                    Console.WriteLine(DateTime.Now.ToString() + "  cx5");
                                                                    if (robotL && robotR)
                                                                    {
                                                                        if (!IsStartMakingL && !IsStartMakingR)
                                                                            CoffeeMaking(coffeeID.classCode, make, ddd.orderNum);
                                                                        //  CoffeeMaking("41103", null, "41103");
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //zsInit++;
                                    //if (zsInit == 10)
                                    //{
                                    //    RobotOperate.CX_Start_L();
                                    //    Console.WriteLine(DateTime.Now.ToString() + "  cx5");
                                    //    if (RobotOperate.pstatusL == JKTYPE.ProgramState.PROGRAM_RUNNING)
                                    //    {
                                    //        IOMsg.Instance.AllBol = false;
                                    //        Thread.Sleep(200);
                                    //        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_ZS_UP);
                                    //        Thread.Sleep(200);
                                    //        while (true)
                                    //        {
                                    //            IOMsg.Instance.RobotBol = false;
                                    //            Thread.Sleep(200);
                                    //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_ZSWC);
                                    //            Thread.Sleep(200);
                                    //            if (IOMsg.Instance.RobotBol)
                                    //            {
                                    //                Thread.Sleep(200);
                                    //                IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_ZS_Down);
                                    //                Thread.Sleep(200);
                                    //                break;
                                    //            }
                                    //        }
                                    //        Thread.Sleep(500);
                                    //        IOMsg.Instance.AllBol = true;
                                    //    }
                                    //    isMake = true;
                                    //    zsInit = 0;
                                    //}
                                }
                            }
                        }
                    }
                    Thread.Sleep(1000);
                }
                catch (Exception)
                {
                    //return;
                    Thread.Sleep(1000);
                }
            }

        }
        public static int CupCode(string code, int cupCode)
        {
            try
            {
                int coffeecode = int.TryParse(code, out int a) ? a : 5001; ;
                switch (code)
                {
                    case "5001"://意式
                        coffeecode = 5001;
                        break;
                    case "5002"://美式
                        if (cupCode == 3)
                            coffeecode = 5009;
                        else
                            coffeecode = 5002;
                        break;
                    case "5003"://卡布
                        if (cupCode == 3)
                            coffeecode = 5010;
                        else
                            coffeecode = 5003;
                        break;
                    case "5005"://拿铁
                        if (cupCode == 3)
                            coffeecode = 5011;
                        else
                            coffeecode = 5004;
                        break;
                    case "5103"://卡布打印
                        if (cupCode == 3)
                            coffeecode = 5110;
                        else
                            coffeecode = 5103;
                        break;
                    case "5105"://拿铁打印
                        if (cupCode == 3)
                            coffeecode = 5111;
                        else
                            coffeecode = 5104;
                        break;
                    case "5214"://冰美式
                        if (cupCode == 3)
                            coffeecode = 5208;
                        else
                            coffeecode = 5214;
                        break;
                    case "5223"://冰拿铁
                        if (cupCode == 3)
                            coffeecode = 5212;
                        else
                            coffeecode = 5223;
                        break;
                }
                return coffeecode;
            }
            catch (Exception)
            {
                return 5001;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="makecoffeeName">50 接咖啡 51 打印 52 加冰 53 拉花</param>
        /// <param name="list"></param>
        /// <param name="orderNum"></param>
        /// <param name="CoffeeBol"></param>
        public static void CoffeeMaking(string makecoffeeName, DeviceOrderQueue list, string orderNum, bool CoffeeBol = true)
        {
            try
            {
                //if (!CoffeeErversysMsg.Instance.IsReadyMilkL)
                //{
                //    isMake = true;
                //    return;
                //}
                if (WuLiaoCoffeeSel.Instance.OutMealCup_Sel_Bol)
                {
                    isMake = true;
                    return;
                }
                //if (!WuLiaoCoffeeSel.Instance.CoffeeBean_Sel_Bol)
                //{
                //    isMake = true;
                //    return;
                //}
                //if (!WuLiaoCoffeeSel.Instance.Water_Sel_Bol)//|| !WuLiaoCoffeeSel.Instance.Water_Sel_Bol || !WuLiaoCoffeeSel.Instance.CupFeed_Sel_Bol
                //{
                //    isMake = true;
                //    return;
                //}
                //if (!WuLiaoCoffeeSel.Instance.PushRodUP_Sel_Bol)
                //{
                //    CoffeeMakes.Instance.MakeMealMsg(orderNum);//出餐
                //}
                var msgs = JsonConvert.DeserializeObject<List<specification>>(list.jsonCodeVal);
                Console.WriteLine(DateTime.Now.ToString() + "  cx10" + list.jsonCodeVal);
                sugarCode = 0;
                cupCode = 1;
                BeanCode = 0;
                if (msgs != null)
                {
                    if (msgs.Any(a1 => a1.SugarCode != ""))
                    {
                        sugarCode = msgs.Any(a1 => a1.SugarCode == "1") ? 1 : msgs.Any(a1 => a1.SugarCode == "2") ? 2 : msgs.Any(a1 => a1.SugarCode == "3") ? 3 : 0;
                    }
                    if (msgs.Any(b => b.CupCode != ""))
                    {
                        cupCode = msgs.Any(b => b.CupCode == "2") ? 2 : msgs.Any(b => b.CupCode == "3") ? 3 : 2;
                    }
                    if (msgs.Any(c => c.BeanCode != ""))
                    {
                        BeanCode = msgs.Any(c => c.BeanCode == "1") ? 1 : msgs.Any(c => c.BeanCode == "2") ? 2 : 1;
                    }
                }
                int code = int.TryParse(makecoffeeName, out int a) ? a : 18001;
                // code = CupCode(makecoffeeName, cupCode);
                int codeMid = code / 1000 % 10;
                int MPCode = code % 1000;
                if (codeMid == 2)
                {
                    if (!IceMakingMsg.Instance.ZBJBol)
                    {
                        isMake = true;
                        return;
                    }

                }
                if (codeMid == 2 || codeMid == 3)
                {
                    var robotBol = RobotModelRight.Instance.RRobotDYD_Sel();
                    Thread.Sleep(300);
                    if (!robotBol)
                    {
                        isMake = true;
                        return;
                    }
                }
                isMake = false;
                Console.WriteLine(DateTime.Now.ToString() + "  cx10" + list.jsonCodeVal);
                SocketClients.Instance.ZBBS = 0;
                SocketClients.Instance.YBBS = 0;
                while (true)
                {
                    EditDeviceOrderStatus editDeviceOrder1 = new EditDeviceOrderStatus();
                    editDeviceOrder1.status = 4;
                    editDeviceOrder1.orderId = list.orderId;
                    editDeviceOrder1.orderGoodsId = list.id;
                    string lit = JsonConvert.SerializeObject(editDeviceOrder1);
                    var ddd1 = HttpMsg.Instance.editDeviceOrderStatusMsg(lit);
                    if (ddd1 != null)
                    {
                        if (ddd1 != "")
                        {
                            var list10 = JsonConvert.DeserializeObject<ListMsg>(ddd1);
                            if (list10 != null)
                            {
                                if (list10.code == "0" || list10.code == "1")
                                {
                                    Console.WriteLine(DateTime.Now.ToString() + "  cx25 " + ddd1);
                                    break;
                                }
                            }
                            Console.WriteLine(DateTime.Now.ToString() + "  cx25 " + ddd1);
                        }
                    }
                    Thread.Sleep(100);
                }
                Thread.Sleep(1000);
                ClientList clientList = new ClientList();
                clientList.MsgBol = WuLiaoCoffeeSel.Instance;
                clientList.code = 10;
                clientList.IsMake = false;
                SocketClients.Instance.client.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                coffeeNameCode = makecoffeeName;
                Img = list.lhImgPath;
                IsStartMakingL = true;
                IsStartMakingR = true;
                while ((SocketClients.Instance.ZBBS == 0) || (SocketClients.Instance.YBBS == 0)) { Thread.Sleep(10); }
                if (codeMid == 3)
                {
                    while (true)
                    {
                        if (CoffeeMakeModel.Instance.IsDLHDL && CoffeeMakeModel.Instance.IsDLHDR)
                        {
                            RobotModelLeft.Instance.RobotJQRTZYXL_UP();
                            RobotModelRight.Instance.RobotJQRTZYXR_UP();
                            Thread.Sleep(1000);
                            RobotModelLeft.Instance.RobotJQRTZYXL_Down();
                            RobotModelRight.Instance.RobotJQRTZYXR_Down();
                            Thread.Sleep(1000);
                            bool robotL = RobotModelLeft.Instance.LRobotJQRYX_Sel();
                            bool robotR = RobotModelRight.Instance.RRobotJQRYX_Sel();
                            if (robotL)
                            {
                                IOMsg.Instance.AllBol = false;
                                Thread.Sleep(100);
                                RobotModelLeft.Instance.RobotLHL_Down();
                                Thread.Sleep(100);
                                IOMsg.Instance.AllBol = true;
                            }
                            if (robotR)
                            {
                                RobotModelRight.Instance.RobotLHR_Down();
                            }
                            if (codeMid == 3 && MPCode == 20)
                                RobotOperate.Robot_Move(10);
                            else if (codeMid == 3 && MPCode == 10)
                                RobotOperate.Robot_Move(22);
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            RobotModelLeft.Instance.RobotLHCCL_UP();
                            Thread.Sleep(200);
                            RobotModelRight.Instance.RobotXBR_UP();
                            Thread.Sleep(100);
                            // Console.WriteLine(DigitalMsg.Instance.LRobot_XBR_UP);
                            Thread.Sleep(100);
                            RobotModelLeft.Instance.RobotJQRYXL_UP();
                            Thread.Sleep(2000);
                            RobotModelRight.Instance.RobotJQRYXR_UP();
                            //RobotOperate.CX_Start_L();
                            //RobotOperate.CX_Start_R();
                            CoffeeMakeModel.Instance.IsLHWCL = true;
                            CoffeeMakeModel.Instance.IsLHWCR = true;
                            while (!CoffeeMakeModel.Instance.IsDXBDR) { Thread.Sleep(10); }
                            while (!CoffeeMakeModel.Instance.IsDCCL) { Thread.Sleep(10); }
                            RobotModelLeft.Instance.RobotJQRYXL_Down();
                            RobotModelRight.Instance.RobotJQRYXR_Down();
                            break;
                        }
                        Thread.Sleep(10);
                    }
                }
                else
                {
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(300);
                    IOMsg.Instance.RobotBol = false;
                    while (true)
                    {
                        Thread.Sleep(300);
                        IOMsg.Instance.RobotBol = RobotModelLeft.Instance.LRobotCCWC_Sel();
                        Thread.Sleep(300);
                        if (IOMsg.Instance.RobotBol)
                        {
                            break;
                        }
                    }
                }

                SocketClients.Instance.IsClear();
                IsStartMakingL = false;
                IsStartMakingR = false;
                // CoffeeMakes.Instance.MakeMealMsg(orderNum);//出餐
                IOMsg.Instance.AllBol = false;
                Thread.Sleep(100);
                IOMsg.Instance.QK();
                IOMsgR.Instance.QK();
                Thread.Sleep(100);
                IOMsg.Instance.AllBol = true;
                while (true)
                {
                    EditDeviceOrderStatus editDeviceOrder1 = new EditDeviceOrderStatus();
                    editDeviceOrder1.status = 5;
                    editDeviceOrder1.orderId = list.orderId;
                    editDeviceOrder1.orderGoodsId = list.id;
                    string lit = JsonConvert.SerializeObject(editDeviceOrder1);
                    var ddd1 = HttpMsg.Instance.editDeviceOrderStatusMsg(lit);
                    if (ddd1 != null)
                    {
                        if (ddd1 != "")
                        {
                            var list10 = JsonConvert.DeserializeObject<ListMsg>(ddd1);
                            if (list10 != null)
                            {
                                if (list10.code == "0" || list10.code == "1")
                                {
                                    Console.WriteLine(DateTime.Now.ToString() + "  cx25 " + ddd1);
                                    break;
                                }
                            }
                            Console.WriteLine(DateTime.Now.ToString() + "  cx25 " + ddd1);
                        }
                    }
                    Thread.Sleep(100);
                }
                bool robotL1 = RobotModelLeft.Instance.LRobotJQRYX_Sel();
                bool robotR1 = RobotModelRight.Instance.RRobotJQRYX_Sel();
                Console.WriteLine(DateTime.Now.ToString() + "  cx5");
                if (robotL1 && robotR1)
                {
                    if (WuLiaoCoffeeSel.Instance.RobotWarn != true)
                    {

                        WuLiaoCoffeeSel.Instance.RobotWarn = true;

                    }
                }
                else
                {
                    if (WuLiaoCoffeeSel.Instance.RobotWarn != false)
                    {
                        WuLiaoCoffeeSel.Instance.RobotWarn = false;

                    }
                }
                ClientList clientList2 = new ClientList();
                clientList2.MsgBol = WuLiaoCoffeeSel.Instance;
                clientList2.code = 2;
                SocketClients.Instance.client.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList2)));
                isMake = true;
            }
            catch (Exception)
            {
                return;
            }
        }

        private void coffee_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                CoffeeErversysMsg.Instance.apiFunctions.DoProductOfDisplay(EversysApi.Defines.ProcSide_t.Left_e, 6);
            }
            catch (Exception)
            {
                return;
            }
        }
    }
}
